﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Input;
using ArchiSimple.Windows.Message;
using ArchiSimple.Windows.ViewModel.PlanObjects;
using GalaSoft.MvvmLight.Command;

namespace ArchiSimple.Windows.ViewModel
{
    public class MenuViewModel : ViewModelBase
    {
        public virtual ICommand PlanCommand { get; set; }

        public virtual ICommand FileCommand { get; set; }

        public virtual ICommand ExitCommand { get; set; }

        public bool IsFile
        {
            get { return this.Get<bool>("IsFile"); }
            set { this.Set<bool>("IsFile", value); }
        }

        public bool IsPlan
        {
            get { return this.Get<bool>("IsPlan"); }
            set { this.Set<bool>("IsPlan", value); }
        }

        public bool IsOpenPlan
        {
            get { return this.Get<bool>("IsOpenPlan"); }
            set { this.Set<bool>("IsOpenPlan", value); }
        }

        public MenuViewModel()
        {
            if (this.IsInDesignMode)
            {
            }
        }

        public PlanObjectViewModel CurrentPlanObject
        {
            get { return this.Get<PlanObjectViewModel>("CurrentPlanObject"); }
            set { this.Set<PlanObjectViewModel>("CurrentPlanObject", value); }
        }


        public override void Init()
        {
            this.NavigationAction = m =>
            {
                if (m.Name == "File")
                {
                    this.IsFile = true;
                    this.IsPlan = false;
                }
                else if(m.Name == "Plan")
                {
                    this.IsPlan = true;
                    this.IsFile = false;
                }
            };

            base.Init();

            this.Register<LoadPlanMessage>(l =>
            {
                this.IsOpenPlan = l.Plan != null;
            });

            this.Register<SelectPlanObjectMessage>(s =>
            {
                this.CurrentPlanObject = s.ViewModel;
            });

            FileCommand = new RelayCommand(() => NavigateTo("File"));
            PlanCommand = new RelayCommand(() => NavigateTo("Plan"));
#if !NETFX_CORE
            ExitCommand = new RelayCommand(() => Application.Current.Shutdown());
#endif
            this.IsFile = true;
        }
    }
}
